<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Slardar script test</title>

  <script>
;(function (w, d, u, b, n, pc, ga, ae, po, s, p, e, t, pp) {
  // constants
  pc = 'precollect'
  ga = 'getAttribute'
  ae = 'addEventListener'
  po = 'PerformanceObserver'

  // placeholder function
  s = function (m) {
    p = [].slice.call(arguments)
    p.push(Date.now(), location.href)
    ;(m == pc ? s.p.a : s.q).push(p)
  }
  s.q = []
  s.p = { a: [] }
  w[n] = s

  // load sdk
  e = document.createElement('script')
  e.src = u + '?bid=' + b + '&globalName=' + n
  e.crossOrigin = u.indexOf('cdn') > 0 ? 'anonymous' : 'use-credentials'
  d.getElementsByTagName('head')[0].appendChild(e)

  // precollect error
  if (ae in w) {
    s.pcErr = function (e) {
      e = e || w.event
      t = e.target || e.srcElement
      if (t instanceof Element || t instanceof HTMLElement) {
        w[n](pc, 'st', { tagName: t.tagName, url: t[ga]('href') || t[ga]('src') })
      } else {
        w[n](pc, 'err', e.error)
      }
    }
    s.pcRej = function (e) {
      e = e || w.event
      w[n](pc, 'reject', e.reason || (e.detail && e.detail.reason))
    }
    w[ae]('error', s.pcErr, true)
    w[ae]('unhandledrejection', s.pcRej, true)
  }

  // precollect performance
  if ('PerformanceLongTaskTiming' in w) {
    pp = s.pp = { entries: [] }
    pp.o = new PerformanceObserver(function (l) {
      pp.entries = pp.entries.concat(l.getEntries)
    })
    pp.o.observe({ entryTypes: ['longtask', 'largest-contentful-paint', 'layout-shift'] })
  }

})(
  window,
  document,
  'http://localhost:8080/cn/apmplus-web.js',
  'sdk-web-script',
  'ApmPlusWebClient',
)

  if (!Cypress.env().doNotInit) {
    window.ApmPlusWebClient('init', Cypress.env().config);
  }
  window.ApmPlusWebClient('on', 'init', () => {
    window.ApmPlusWebClient?.getSender()?.setSize(0)
    window.ApmPlusWebClient?.getSender()?.setWait(0)
  })
  </script>
  <script type="text/javascript">
    window.loadScript = function (url, callback) {
      var script = document.createElement('script');
      var head = document.head;
      if (callback) {
        script.addEventListener('load', callback);
      }
      script.src = url;
      script.async = true;
      script.crossOrigin = 'anonymous';
      head.insertBefore(script, head.firstChild);
    };
  </script>
  <script type="text/javascript">
    window.loadLink = function (url, callback) {
      var link = document.createElement('link');
      var head = document.head;
      if (callback) {
        link.addEventListener('load', callback);
      }
      link.href = url;
      link.rel = "stylesheet"
      link.type = "text/css"
      head.insertBefore(link, head.firstChild);
    };
  </script>
</head>

<body>
  <div id="app"></div>
</body>

</html>
